//
//  LeadViewController.m
//  Restaurant
//
//  Created by wanghuan on 15/4/20.
//  Copyright (c) 2015年 wanghuan. All rights reserved.
//

#import "LeadViewController.h"
#define SHeight self.imageScrollerView.frame.size.height
#define SWidth self.imageScrollerView.frame.size.width

@interface LeadViewController ()

@end

@implementation LeadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBarHidden = YES;
    
    self.view.backgroundColor = AppBackGroundColor;
    
    self.imageScrollerView.frame = CGRectMake(0,0, APPWith, APPHeight-20);

    self.imageScrollerView.pagingEnabled = YES;
    
    self.imageScrollerView.alwaysBounceHorizontal = NO;
    
    self.imageScrollerView.alwaysBounceVertical = NO;
    
    NSArray *ImageArray = @[[UIColor redColor],[UIColor orangeColor],[UIColor yellowColor]];
    
    NSArray *btnTitleArr = @[@"立即体验",@"用户注册"];
    
    for (int i = 0; i < 3; i++) {
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i*SWidth, 0, SWidth, SHeight)];
        imageView.backgroundColor = ImageArray[i];
        
        imageView.userInteractionEnabled = YES;
        
//        UIButton *jump = [UIButton buttonWithType:UIButtonTypeCustom];
//        jump.frame = CGRectMake(0, 0, 30, 25);
        
        
        if (i==2) {
           
            for (int t = 0; t < 2; t++) {
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button setTitle:btnTitleArr[t] forState:UIControlStateNormal];
                [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                button.tag = t+1;
                
            if (!t) {
                button.frame = CGRectMake(40, SHeight-130, SWidth-80, 40);
                button.titleLabel.font = [UIFont systemFontOfSize:16];
                button = (UIButton *)[[SuperView defaultView]addView:button borderColor:nil cornerRadius:5 borderWidth:0];
                button.backgroundColor = [UIColor whiteColor];
               
                    
                } else {
                
                    button.frame = CGRectMake(SWidth-10-88, SHeight-40, 88, 40);
                }
                
                [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
                

                [imageView addSubview:button];
                
            }
            
        }
        
        
        [self.imageScrollerView addSubview:imageView];
    }
    
    self.imageScrollerView.delegate = self;
    
    self.imageScrollerView.contentSize = CGSizeMake(SWidth*3, 0);
    
    

}

- (void)btnClick:(UIButton *)sender {
    
    if (sender.tag == 1) {
        
        MenuViewController *mvc = [[MenuViewController alloc]init];
        
        [self.navigationController pushViewController:mvc animated:YES];
        return;
    }
    
    RegisterViewController *rvc = [[RegisterViewController alloc]init];
    
    [self.navigationController pushViewController:rvc animated:YES];

    
    

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
//    int page = scrollView.contentOffset.x/SWidth;
    
//    if (page == 0) {
//        scrollView.contentOffset = CGPointMake(SWidth*3, 0);
//    }
//    
//    if (page == 4) {
//        scrollView.contentOffset = CGPointMake(SWidth, 0);
//    }


    self.pageControl.currentPage  =scrollView.contentOffset.x/SWidth;
//    _timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(scrollTimer) userInfo:nil repeats:YES];

}



//-(void)scrollTimer {
//
//    _timeCount ++;
//    
//    if (_timeCount == 4) {
//        self.pageControl.currentPage = 0;
//        
//        _timeCount = 1;
//        
//    }
//    
//    self.imageScrollerView.contentOffset = CGPointMake(_timeCount*SWidth, 0);
//    
//
//    
//    self.pageControl.currentPage = (NSInteger)self.imageScrollerView.contentOffset.x/SWidth-1;
//    
//   
//
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)jumpBtn:(UIButton *)sender {

    sender.tag = 1;
    [self btnClick:sender];

}


@end
